aura_env.var = {}
if aura_env.var["num"] == nil then aura_env.var["num"] = 0 end
if aura_env.var["kill_count"] == nil then aura_env.var["kill_count"] = 0 end
if aura_env.var["flag_inout_Instance"] == nil then aura_env.var["flag_inout_Instance"] = 1 end  -- 进出副本标记变量
if aura_env.var["start_time"]  == nil then aura_env.var["start_time"] = GetTime() end
if aura_env.var["end_time"]  == nil then aura_env.var["end_time"] = 0 end
if aura_env.var["start_exp"] == nil then aura_env.var["start_exp"] = UnitXP("player") end
if aura_env.var["start_level"] == nil then aura_env.var["start_level"] = UnitLevel("player") end
if aura_env.var["start_levelexpmax"] == nil then aura_env.var["start_levelexpmax"] = UnitXPMax("player") end
if aura_env.var["total_exp"] == nil then aura_env.var["total_exp"] = 0 end
if aura_env.var["total_time"] == nil then aura_env.var["total_time"] = 0 end
if aura_env.var["exp_per_time"] == nil then aura_env.var["exp_per_time"] = 0 end
if aura_env.var["total_time_min"] == nil then aura_env.var["total_time_min"] = 0 end
if aura_env.var["total_time_sec"] == nil then aura_env.var["total_time_sec"] = 0 end
if aura_env.var["isUILoadingFinish"]  == nil then aura_env.var["isUILoadingFinish"] = 0 end
local faction_info = {GetWatchedFactionInfo()}  --获取当前经验条声望信息
if faction_info[1] ~= nil then
    if aura_env.var["faction_name"]  == nil then aura_env.var["faction_name"] = faction_info[1] end
    if aura_env.var["faction_start"]  == nil then aura_env.var["faction_start"] = faction_info[5] end
else
    if aura_env.var["faction_name"]  == nil then aura_env.var["faction_name"] = "-" end
    if aura_env.var["faction_start"]  == nil then aura_env.var["faction_start"] = 0 end
end

--感谢林登添加可点击功能代码
if aura_env.config["isClickReset"] then
    local chatFrame = SELECTED_DOCK_FRAME
    local inputbox = chatFrame.editBox
    local e = aura_env
    local region = WeakAuras.GetRegion(e.id)
    aura_env.haka_items_t={}
    if not _G[e.id.."Button"] then
        e.btn = CreateFrame("Button", e.id.."Button", region)
        e.btn:RegisterForClicks("AnyUp")
        e.btn:SetAllPoints(region)
    end
    
    local btn = _G[e.id.."Button"]
    
    btn:SetScript("OnClick", function(self, clickbutton, down)
            if e.config["isdebug"] then print(date("%H:%M:%S") .. " [DEBUG]" .. clickbutton) end
            local setbutton = ""
            if e.config["mouse_reset"] == 1 then
                setbutton = "LeftButton"
            elseif e.config["mouse_reset"] == 2 then
                setbutton = "MiddleButton"
            elseif e.config["mouse_reset"] == 3 then
                setbutton = "RightButton"
            elseif e.config["mouse_reset"] == 4 then
                setbutton = "Button4"
            elseif e.config["mouse_reset"] == 5 then
                setbutton = "Button5"
            end
            
            if clickbutton ~= setbutton then
                if setbutton == "LeftButton" then
                    print("[ExpHelper] 单击鼠标左键重置")
                elseif setbutton == "MiddleButton" then
                    print("[ExpHelper] 单击鼠标中键重置")
                elseif setbutton == "RightButton" then
                    print("[ExpHelper] 单击鼠标右键重置")
                elseif setbutton == "Button4" then
                    print("[ExpHelper] 单击鼠标4键重置")
                elseif setbutton == "Button5" then
                    print("[ExpHelper] 单击鼠标5键重置")
                end
            else
                if e.config["isResetNum"] then e.var["num"] = 0 end
                e.var["kill_count"] = 0
                e.var["isUILoadingFinish"] = 0
                if IsInInstance() then e.var["flag_inout_Instance"] = 0 else e.var["flag_inout_Instance"] = 1 end
                e.var["start_time"] = GetTime()
                e.var["end_time"] = 0
                e.var["start_exp"] = UnitXP("player")
                e.var["start_level"] = UnitLevel("player")
                e.var["start_levelexpmax"] = UnitXPMax("player")
                e.var["total_exp"] = 0 
                e.var["total_time"] = 0 
                e.var["exp_per_time"] = 0 
                e.var["total_time_min"] = 0 
                e.var["total_time_sec"] = 0
                local faction_info = {GetWatchedFactionInfo()}  --获取当前经验条声望信息
                if faction_info[1] ~= nil then  -- ==nil则没有声望条
                    e.var["faction_name"] = faction_info[1]
                    e.var["faction_start"] = faction_info[5]
                else
                    e.var["faction_name"] = "-"
                    e.var["faction_start"] = 0
                end
                print('[ExpHelper] 数据已重置')
            end
    end)
    btn:SetScript("OnMouseUp", function(self)
            region:SetAlpha(1)
    end)
    btn:SetScript("OnMouseDown", function(self)
            region:SetAlpha(0.5)
    end)
    --[[btn:SetScript("OnEnter",function(self)
            region:SetScale(1.01)
    end)
    btn:SetScript("OnLeave",function(self)
            region:SetScale(1)
    end)]]
end

